#include "headfiles.h"

using namespace std;

#define MAX 1000000

void printWordsLessThan1000(int n) {
    int res, tenth;
    res = n / 100;
    tenth = n % 100;
    if (res > 0) {
        cout << str_num[res];
        cout << " hundred";

        if (tenth > 0) {
            cout << " and ";
        }
    }

    res = tenth / 10;
    if (res > 1) {
        cout << str_tenth[res] << " ";
        res = tenth % 10;
        if (res > 0) {
            cout << str_num[res];
        }
    }
    else {
        if (tenth > 0) {
            cout << str_num[tenth];
        }
    }

    return;
}

void printWords(int n) {
    if (n >= (MAX)) {
        cout << "Input number is too big!" << endl;
        return;
    }

    int res = n;
    if (res >= 1000) {
        printWordsLessThan1000(res / 1000);
        res = res % 1000;
        cout << " thousand ";
        printWordsLessThan1000(res);
    }
    else {
        printWordsLessThan1000(res);
        if (res == 0) {
            cout << str_num[res];
        }
    }

    return;
}
